package com.zyy.zyy.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import sun.dc.pr.PRError;

import java.util.Properties;

/**
 * Create by chenlipeng on 2021/08/20 12:04
 */
//验证码配置类
@Component
public class KaptchaConfig {
    
    @Bean
    public DefaultKaptcha getDefaultKaptcha(){
        com.google.code.kaptcha.impl.DefaultKaptcha defaultKaptcha=new com.google.code.kaptcha.impl.DefaultKaptcha();
        Properties properties=new Properties();
        //图片边框
        properties.put("Kaptcha.border","no");
        //字体颜色
        properties.put("Kaptcha.textproducer.font.color","black");
        //图片宽
        properties.put("Kaptcha.image.width","160");
        //图片高
        properties.put("Kaptcha.image.height","40");
        //字体大小
        properties.put("Kaptcha.textproducer.font.size","30");
        //验证码长度
        properties.put("Kaptcha.textproducer.font.space","5");
        //字体
        properties.setProperty("Kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");
        Config  config=new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
